import socket
import time
from threading import Thread, currentThread, activeCount


def send_json_message(conn, message):
    conn.sendall(bytes(message, encoding="utf-8"))


def receive(conn):
    print("receive:\n")
    while True:
        rec = str(conn.recv(1024), encoding="utf-8")
        print("line: " + rec)


if __name__ == "__main__":
    sk = socket.socket()
    sk.bind(("127.0.0.1", 8112))
    sk.listen(5)
    conn, address = sk.accept()
    t2 = Thread(target=receive, args=(conn,))
    t2.setDaemon(True)
    t2.start()
    while True:
        conn.send(bytes("{x:9,y:9}", encoding="utf-8"))
        time.sleep(1);
